package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-20 17:28
 **/
public class LeetCode494 {
    int count = 0;

    public int findTargetSumWays(int[] nums, int target) {
        recur(nums, 0, 0, target);
        return count;
    }

    void recur(int[] nums, int cur, int sum, int target) {
        if (cur == nums.length) {
            if (sum == target) {
                ++count;
            }
            return;
        }
        recur(nums, cur + 1, sum + nums[cur], target);
        recur(nums, cur + 1, sum - nums[cur], target);
    }

    public static void main(String[] args) {
        LeetCode494 code = new LeetCode494();
        System.out.println(code.findTargetSumWays(new int[]{1, 1, 1, 1, 1}, 3));
    }
}
